package in.srain.cube.views.ptr;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class PtrClassicFrameLayout extends PtrFrameLayout {

	private PtrClassicDefaultHeader mPtrClassicHeader;
	private PtrClassicDefaultFooter mPtrClassicFooter;

	public PtrClassicFrameLayout(Context context) {
		super(context);
		initViews();
	}

	public PtrClassicFrameLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		initViews();
	}

	public PtrClassicFrameLayout(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		initViews();
	}

	private void initViews() {
		mPtrClassicHeader = new PtrClassicDefaultHeader(getContext());
		setHeaderView(mPtrClassicHeader);
		addPtrUIHandler(mPtrClassicHeader);
		mPtrClassicFooter = new PtrClassicDefaultFooter(getContext());
		setFooterView(mPtrClassicFooter);
		addPtrUIHandler(mPtrClassicFooter);
	}

	public PtrClassicDefaultHeader getHeader() {
		return mPtrClassicHeader;
	}

	/**
	 * Specify the last update time by this key string
	 * 
	 * @param key
	 */
	public void setLastUpdateTimeKey(String key) {
		setLastUpdateTimeHeaderKey(key);
		setLastUpdateTimeFooterKey(key);
	}

	public void setLastUpdateTimeHeaderKey(String key) {
		if (mPtrClassicHeader != null) {
			mPtrClassicHeader.setLastUpdateTimeKey(key);
		}
	}

	public void setLastUpdateTimeFooterKey(String key) {
		if (mPtrClassicFooter != null) {
			mPtrClassicFooter.setLastUpdateTimeKey(key);
		}
	}

	/**
	 * Using an object to specify the last update time.
	 * 
	 * @param object
	 */
	public void setLastUpdateTimeRelateObject(Object object) {
		setLastUpdateTimeHeaderRelateObject(object);
		setLastUpdateTimeFooterRelateObject(object);
	}

	public void setLastUpdateTimeHeaderRelateObject(Object object) {
		if (mPtrClassicHeader != null) {
			mPtrClassicHeader.setLastUpdateTimeRelateObject(object);
		}
	}

	public void setLastUpdateTimeFooterRelateObject(Object object) {
		if (mPtrClassicFooter != null) {
			mPtrClassicFooter.setLastUpdateTimeRelateObject(object);
		}
	}

	@Override
	public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {

		super.disableWhenHorizontalMove(disallowIntercept);
	}

}
